package com.gpframework.module.controller.module;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.gpframework.common.exception.ParamException;
import com.gpframework.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.module.domain.GpYiliInventoryInformation;
import com.gpframework.module.module.domain.vo.GpYiliInventoryInformationVo;
import com.gpframework.module.module.domain.req.GpYiliInventoryInformationReq;
import com.gpframework.module.module.domain.req.GpYiliInventoryInformationAdd;
import com.gpframework.module.module.domain.req.GpYiliInventoryInformationUpdate;
import com.gpframework.module.module.service.IGpYiliInventoryInformationService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpYiliInventoryInformationController
 * @Author gpframework
 * @Date 2024-02-22
 * @Version 1.0.0
 * @Description 衣丽库存信息Controller 接口类
 */
@Validated
@Api(tags = "衣丽库存信息")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/yiliInventoryInformation" )
public class GpYiliInventoryInformationController extends BaseController {

    private final IGpYiliInventoryInformationService iGpYiliInventoryInformationService;

    /**
     * @Description 分页
     * @Author gpframework
     * @Date 2024-02-22
     * @Param gpYiliInventoryInformation
     * @Return TableDataInfo
     */
    @ApiOperation("列表")
    @GetMapping("/list")
    public TableDataInfo<GpYiliInventoryInformationVo> list(GpYiliInventoryInformationReq gpYiliInventoryInformationReq)
    {
        startPage();
        QueryWrapper<GpYiliInventoryInformation> lqw = new QueryWrapper<GpYiliInventoryInformation>();
        gpYiliInventoryInformationReq.generatorQuery(lqw,true);
        if (StringUtils.isNotBlank(gpYiliInventoryInformationReq.getProductName())) {
            lqw.eq("gp.product_name", gpYiliInventoryInformationReq.getProductName());
        }
        lqw.orderByAsc("gp.colour");
        lqw.orderByAsc("LENGTH(gp.colour)");
        List<GpYiliInventoryInformationVo> list = iGpYiliInventoryInformationService.listVo(lqw);
        return getDataTable(list);
    }


    /**
     * @Description 货架一级列表
     * @Author gpframework
     * @Date 2024-02-22
     * @Param gpYiliInventoryInformation
     * @Return TableDataInfo
     */
    @ApiOperation("货架一级列表")
    @GetMapping("/yiliInventoryInformationList")
    public TableDataInfo<GpYiliInventoryInformationVo> yiliInventoryInformationList(GpYiliInventoryInformationReq gpYiliInventoryInformationReq)
    {
        startPage();
        QueryWrapper<GpYiliInventoryInformation> lqw = new QueryWrapper<GpYiliInventoryInformation>();
        gpYiliInventoryInformationReq.generatorQuery(lqw,true);
        if (StringUtils.isNotBlank(gpYiliInventoryInformationReq.getProductName())){
            lqw.like("gp.product_name", gpYiliInventoryInformationReq.getProductName());
        }
        lqw.groupBy("gp.product_name");
        lqw.orderByAsc("LENGTH(gp.product_name)");
        lqw.orderByAsc("gp.product_name");
        List<GpYiliInventoryInformationVo> list = iGpYiliInventoryInformationService.listVo(lqw);
        return getDataTable(list);
    }


    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2024-02-22
     * @Param gpYiliInventoryInformation
     * @Return AjaxResult
     */
    @ApiOperation("详情")
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpYiliInventoryInformationVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpYiliInventoryInformationService.getVoById(id));
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-02-22
     * @Param gpYiliInventoryInformation
     * @Return AjaxResult
     */
    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpYiliInventoryInformationAdd gpYiliInventoryInformationAdd) {
        GpYiliInventoryInformation gpYiliInventoryInformation = Convert.convert(new TypeReference<GpYiliInventoryInformation>() {}, gpYiliInventoryInformationAdd);
        return toAjax(iGpYiliInventoryInformationService.save(gpYiliInventoryInformation) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-02-22
     * @Param gpYiliInventoryInformation
     * @Return AjaxResult
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpYiliInventoryInformationUpdate gpYiliInventoryInformationUpdate) {
        GpYiliInventoryInformation gpYiliInventoryInformation = Convert.convert(new TypeReference<GpYiliInventoryInformation>() {}, gpYiliInventoryInformationUpdate);
        return toAjax(iGpYiliInventoryInformationService.updateById(gpYiliInventoryInformation) ? 1 : 0);
    }

    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2024-02-22
     * @Param gpYiliInventoryInformation
     * @Return AjaxResult
     */
    @ApiOperation("删除")
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpYiliInventoryInformationService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
